//
//  CZNetworkTool.swift
//  CZWeibo
//
//  Created by 周振兰 on 16/5/12.
//  Copyright © 2016年 周振兰. All rights reserved.
//

import UIKit
import AFNetworking
enum RequestMethod: String
{
    case GET = "GET"
    case POST = "POST"
}
class CZNetworkTool: NSObject
{
    //单例
    static let shareaIntance : CZNetworkTool = CZNetworkTool()
    //属性
    private var afnManger: AFHTTPSessionManager
        {
       
            let afn = AFHTTPSessionManager(baseURL: NSURL(string: "https://api.weibo.com/"))
            afn.responseSerializer.acceptableContentTypes?.insert("text/plain")
            return afn
    }
    
    
    func request(method: RequestMethod, URLString: String, parameters: AnyObject?, success: ((NSURLSessionDataTask, AnyObject?) -> Void)?, failure: ((NSURLSessionDataTask?, NSError) -> Void)?)
    {
        if method == RequestMethod.GET
        {
            afnManger.GET(URLString, parameters: parameters, progress: nil , success: success, failure: failure)
        }else
        {
            afnManger.POST(URLString, parameters: parameters, progress: nil , success: success, failure: failure)
        }
    }
}

